﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Xml.Linq;
using System.Web;

namespace Medianamik.Core.Logging
{
    public class HttpCookieCollectionTableBuilder : TableBuilder 
    {
        public HttpCookieCollection Collection
        {
            get;
            private set;
        }

        public string TableTitle
        {
            get;
            private set;
        }

        public HttpCookieCollectionTableBuilder(HttpCookieCollection pCollection, string pTableTitle)
        {
            Collection = pCollection;
            TableTitle = pTableTitle;
        }

        protected override void Build(XElement table )
        {
            table.Add(BuildHeaderRow(TableTitle, 2));
            var keys = Collection.AllKeys.ToList();
            var i=0;
            keys.ForEach((key) =>
            {
                HttpCookie c = Collection[key];
                if (c != null)
                {
                    table.Add(BuildRow(key, c.Value, ++i%2==0 ));
                }
            });
        }
    }
}
